import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete
} from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { UserService } from './user.service';
import { UpdateUserDto, createUserDto } from 'libs/db/src/schemas';
import { QueryUserDto } from './dto/queryUserDto';
import { userNormalize as norm } from '../../normalize';

@Controller(norm.path)
@ApiBearerAuth() // 添加BearerAuth装饰器
@ApiTags(norm.tag)
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post(norm.create.path)
  @ApiOperation({ summary: norm.create.tag })
  async create(@Body() createUserDto: createUserDto) {
    return await this.userService.create(createUserDto);
  }

  @ApiOperation({ summary: norm.page.tag })
  @Post(norm.page.path)
  pageQuery(@Body() dto: QueryUserDto) {
    return this.userService.pageQuery(dto);
  }

  @ApiOperation({ summary: norm.list.tag })
  @Get(norm.list.path)
  async findAll() {
    return await this.userService.findAll();
  }

  @ApiOperation({ summary: norm.detail.tag })
  @Get(norm.detail.path)
  async findOne(@Param(norm.detail.arg) id: string) {
    return await this.userService.findById(id);
  }

  @ApiOperation({ summary: norm.update.tag })
  @Patch(norm.update.path)
  async update(
    @Param(norm.update.arg) id: string,
    @Body() updateUserDto: UpdateUserDto
  ) {
    return await this.userService.update(id, updateUserDto);
  }

  @ApiOperation({ summary: norm.delete.tag })
  @Delete(norm.delete.path)
  async remove(@Param(norm.delete.arg) id: string) {
    return await this.userService.remove(id);
  }
}
